package hadoop.mapreduce.partitionsort;


import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Partitioner;

public class ProvincePartitioner extends Partitioner<PhoneBean,Text> {

    /**
     * 5个分区,从0开始
     * @param text 与mapper输出一致
     * @param phoneBean 与mapper输出一致
     * @param numPartitions
     * @return
     */
    @Override
    public int getPartition(PhoneBean phoneBean, Text text,  int numPartitions) {
        int partition =4;
        String beginPhone = text.toString().substring(0, 3);
        if ("136".equals(beginPhone)){
            partition=0;
        }
        if ("137".equals(beginPhone)){
            partition=1;
        }
        if ("138".equals(beginPhone)){
            partition=2;
        }
        if ("139".equals(beginPhone)){
            partition=3;
        }
        return partition ;
    }

}
